package com.aphrodite.io;

import java.io.IOException;
import java.io.OutputStream;

import javax.microedition.io.Connector;

/**
 * OutputStream for writing data to the file system
 */
public class FileOutputStream extends OutputStream {
	OutputStream os;

	/** Creates a new FileOutputStream. */
	public FileOutputStream(FileOutputStream fileoutstream) {
		os = fileoutstream.os;
	}

	/** Creates a new FileOutputStream. */
	public FileOutputStream(String filename) throws IOException {
		os = Connector.openOutputStream("file://" + filename);
	}

	/** Creates a new FileOutputStream. */
	public FileOutputStream(String filename, boolean append) throws IOException {
		os = Connector.openOutputStream("file://" + filename);
	}

	/**
	 * Closes this output stream and releases any system resources associated
	 * with this stream.
	 */
	public void close() throws IOException {
		os.close();
	}

	/**
	 * Flushes this output stream and forces any buffered output bytes to be
	 * written out.
	 */
	public void flush() throws IOException {
		os.flush();
	}

	/**
	 * Writes b.length bytes from the specified byte array to this output
	 * stream.
	 */
	public void write(byte[] b) throws IOException {
		os.write(b);
	}

	/**
	 * Writes len bytes from the specified byte array starting at offset off to
	 * this output stream.
	 */
	public void write(byte[] b, int off, int len) throws IOException {
		os.write(b, off, len);
	}

	/** Writes the specified byte to this output stream. */
	public void write(int b) throws IOException {
		os.write(b);
	}

}